﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        #region 注册
        private void button4_Click(object sender, EventArgs e)
        {
            //转到下一个窗体
            Register register = new Register();
            register.Show();
        }
        #endregion

        #region 登录
        private void button3_Click(object sender, EventArgs e)
        {
            //移除字符串的空白字符
            string a = uid.Text.Trim();
            string b = pwd.Text.Trim();

            //连接数据库
            string connect = "server=LAPTOP-AS39K086\\MSSQLSERVER1;uid=HUANG;pwd=571193002;database=WinFrom";
            SqlConnection sqlConnection = new SqlConnection(connect);
            sqlConnection.Open();

            //判断输入的内容是否与数据库内容一致
            string sqlOrder = "select * from Login where phone='" + a + "' or email='" + a + "' and pwd='" + b + "'";
            SqlCommand sqlCommand = new SqlCommand(sqlOrder, sqlConnection);
            //通过影响的行数来判断是否输入正确
            var show = sqlCommand.ExecuteReader();
            if (show.Read())
            {
                CMD show1 = new CMD();
                show1.Show();
            }
            else
            {
                MessageBox.Show("账号或密码错误", "提示");
            }
            sqlConnection.Close();
        }
        #endregion

        #region 账号
        private void textBox1_MouseClick(object sender, MouseEventArgs e)
        {
            //当鼠标点击文本框时(MouseClick)，文本框的内容为空
            uid.Text = null;
        }
        #endregion

        #region 忘记密码
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            ForgetPwd forgetPwd = new ForgetPwd();
            forgetPwd.Show();
        }
        #endregion
    }
}
